/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package l2bot.interfaz.dialogs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.ListSelectionModel;
import javax.swing.SpringLayout;
import javax.swing.table.DefaultTableModel;
import l2bot.pj.handlers.CharSelectHandler;
import l2bot.pj.handlers.CharSelectHandler.Char;
/**
 *
 * @author carl
 */
public class CharSelectDialog extends JDialog{
    DefaultTableModel tm;
    CharSelectHandler csh;
   
    public CharSelectDialog(java.awt.Frame parent, CharSelectHandler _csh) {
        super(parent, false);
        
        tm = new DefaultTableModel();
        tm.addColumn("Nombre");
        tm.addColumn("Raza");
        tm.addColumn("Clase");
        tm.addColumn("Nivel");
        initComponents();
        
        jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        
        for (int i = 0; i < _csh.chars.size(); i++) {
            Char ch = _csh.chars.get(i);
            addChar(ch.nombre,ch.raza.name(),ch.clase.name(),ch.lvl);
            
        }
        csh = _csh;      
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")

    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable(){
            @Override
            public Class getColumnClass(int column)
            {
                    return getValueAt(0, column).getClass();
            }
        };
 
			//  Apply background to existing renderer
 
        //colorRenderer.startBlinking(1000);


        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

       // jTable1.setAutoCreateColumnsFromModel(false);
       // jTable1.setAutoCreateRowSorter(true);
        
        jTable1.setModel(tm);
        
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onAceptar((byte) jTable1.getSelectedRow());
                setVisible(false);
            }
        });
        

        jButton2.setText("Mostrar Info");
        jButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                DialogosComunes.mostrarTexto(csh.chars.get(jTable1.getSelectedRow()).toString());
            }
        });
        jButton3.setText("Log-out");
        jButton3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            }
        });
        jButton4.setText("Nuevo"); //implementar
        jButton4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            }
        });        
        
        add(jScrollPane1);
        add(jButton1);
        add(jButton2);
        add(jButton3);
        add(jButton4);
        SpringLayout layout = new SpringLayout();
        layout.putConstraint(SpringLayout.NORTH, jScrollPane1, 5, SpringLayout.NORTH, this.getContentPane());
        layout.putConstraint(SpringLayout.WEST,jScrollPane1, 5, SpringLayout.WEST, this);
        layout.putConstraint(SpringLayout.EAST,jScrollPane1, -5, SpringLayout.EAST, this);
        layout.putConstraint(SpringLayout.EAST, this.getContentPane(), 5, SpringLayout.EAST, jButton3);
        layout.putConstraint(SpringLayout.NORTH, jButton1, 5, SpringLayout.SOUTH, jScrollPane1);
        layout.putConstraint(SpringLayout.NORTH, jButton2, 5, SpringLayout.SOUTH, jScrollPane1);
        layout.putConstraint(SpringLayout.NORTH, jButton3, 5, SpringLayout.SOUTH, jScrollPane1);
        layout.putConstraint(SpringLayout.NORTH, jButton4, 5, SpringLayout.SOUTH, jScrollPane1);
        layout.putConstraint(SpringLayout.WEST, jButton1, 5, SpringLayout.WEST, this.getContentPane());
        layout.putConstraint(SpringLayout.WEST, jButton2, 5, SpringLayout.EAST, jButton1);
        layout.putConstraint(SpringLayout.WEST, jButton4, 5, SpringLayout.EAST, jButton2);
        layout.putConstraint(SpringLayout.WEST, jButton3, 5, SpringLayout.EAST, jButton4);
        
        layout.putConstraint(SpringLayout.SOUTH, this.getContentPane(), 5, SpringLayout.SOUTH, jButton1);
        setLayout(layout);
        pack();
    }

    
    public void addChar(String nombre, String clase,String raza,int lvl){
        String[] ser = {nombre, raza, clase, String.valueOf(lvl)};
        tm.addRow(ser);
    }
    
    public void onAceptar(byte ch){}
    public void onCancelar(){}
    public void onNuevo(){}

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration

}
